<template>
    <div>
        <!-- 表格 -->
        <el-table :data="list" style="width: 100%">
            <el-table-column prop="id" label="编号" width="180"></el-table-column>
            <el-table-column prop="realname" label="姓名" width="180"></el-table-column>
            <el-table-column prop="tel" label="电话"></el-table-column>
            <el-table-column prop="createtime" :formatter="fmt" label="登记时间"></el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination background @size-change="handleSizeChange"
                       @current-change="handleCurrentChange"
                       :current-page.sync="pageIndex" layout="prev, pager, next" :total="1000   "></el-pagination>
    </div>
</template>
    <style scoped>
</style>
<script>
    import util from "@/utils/mymethods.js";
    export default {
        name: "shiting",
        data() {
            return {
                list: [],
                pageIndex: 1
            };
        },
        created() {
            this.getlist();
        },
        methods:{
             async getlist() {
                // this.$axios.get('http://47.92.50.43:8888/sys/shitinglist').then()
                let res = await this.$axios.get(
                    "http://47.92.50.43:8888/sys/shitinglist",
                    {
                        params: {
                            keywords: "",
                            pageIndex: this.pageIndex,
                            pageSize: 10
                        }
                    }
                );
                console.log(res);
                this.list = res.data;
            },
            fmt(row, column, cellValue, index) {
                return new Date(cellValue).changeTime();
            },
            handleDelete(index, row) {
                console.log(index, row.id);
                this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(async () => {
                    let res  = await  this.delItem(row.id)
                    if(res){this.$message({type: 'success',message: '删除成功!'}) ;  this.getlist();}
                    else this.$message.error('删除失败');

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });

            },
            async delItem(id){
                // this.$axios.post('http://47.92.50.43:8888/sys/removest',{id:id}).the
                let res = await this.$axios.post('http://47.92.50.43:8888/sys/removest',{id:id});
                console.log(res)
                return res.data.success
            },
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.getlist()
            },

        }
    };
</script>